home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Utilities / vim-5.1 / syntax / sh.vim < prev    next >
Encoding:
Text File  |  1998-03-29  |  8.9 KB  |  200 lines

  1. " Vim syntax file
  2. " Language:    shell (sh) Korn shell (ksh) bash (sh)
  3. " Maintainer:    Lennart Schultz <Lennart.Schultz@ecmwf.int>
  4. " Last change:    1997 November 24
  5. "
  6. " Using the following VIM variables:
  7. " is_kornshell               if defined enhance with kornshell syntax
  8. " is_bash                    if defined enhance with bash syntax
  9. "
  10. " This is a complete redesign including many ideas from
  11. " Éric Brunet (eric.brunet@ens.fr)
  12. "
  13. " Updated 1997 November 21
  14. "    With many good inputs from Éric Brunet, especially he got the
  15. "    case statement to work!
  16. " Updated 1997 November 24
  17. "     Sync included with thanks to Dr. Charles E. Campbell Jr <cec@gryphon.gsfc.nasa.gov>
  18. "    Echo included with thanks to Éric Brunet
  19. "    [ \t] removed using \s instead
  20. " Updated 1998 March 24
  21. "       Error in case statement corrected with thanks to  Ronald.Schild rs@dps.de
  22. " Updated 1998 March 25
  23. "       Error correction from Dr. Charles E. Campbell Jr 
  24. " Updated 1998 March 29
  25. "    added sh_minlines (Bram Moolenaar)
  26.  
  27. " Remove any old syntax stuff hanging around
  28. syn clear
  29. " sh syntax is case sensitive
  30. syn case match
  31.  
  32. syn keyword    shTodo        contained TODO
  33. syn match    shComment        "#.*$" contains=shTodo
  34.  
  35. " String and Character constants
  36. "===============================
  37. syn match   shNumber       "-\=\<[0-9]\+\>"
  38. syn match   shSpecial      contained "\\[0-9][0-9][0-9]\|\\[abcfnrtv]"
  39. syn region  shSinglequote matchgroup=shOperator start=+'+ end=+'+
  40. syn region  shDoubleQuote      matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=shDeref,shCommandSub,shSpecialShellVar,shSpecial
  41. syn match  shSpecial  "\\[\\\"\'`$]"
  42.     " This must be after the strings, so that bla \" be correct
  43. syn region shEmbeddedEcho contained matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|`]"me=e-1 end="[0-9][<>]"me=e-2 end="#"me=e-1 contains=shNumber,shSinglequote,shDeref,shSpecialVar,shSpecial,shOperator,shDoubleQuote
  44.      " This one is needed INSIDE a CommandSub, so that
  45.      " `echo bla` be correct
  46. syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|]"me=e-1 end="[0-9][<>]"me=e-2 end="#"me=e-1 contains=shNumber,shCommandSub,shSinglequote,shDeref,shSpecialVar,shSpecial,shOperator,shDoubleQuote
  47.  
  48. "Error Codes
  49. syn match   shDoError "\<done\>"
  50. syn match   shIfError "\<fi\>"
  51. syn match   shInError "\<in\>"
  52. syn match   shCaseError ";;"
  53. syn match   shEsacError "\<esac\>"
  54. syn match   shCurlyError "}"
  55. syn match   shParenError ")"
  56. if exists("is_kornshell")
  57. syn match     shDTestError "]]"
  58. endif
  59. syn match     shTestError "]"
  60.  
  61. " Tests
  62. "======
  63. if exists("is_kornshell")
  64. syn region  shNone transparent matchgroup=shOperator start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=ALLBUT,shFunction,shTestError,shIdentifier,shCase,shDTestError
  65. endif
  66. syn region  shNone transparent matchgroup=shOperator start="\[" skip=+\\\\\|\\$+ end="\]" contains=ALLBUT,shFunction,shTestError,shIdentifier,shCase,shDTestError
  67. syn region  shNone transparent matchgroup=shStatement start="\<test\>" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=ALLBUT,shFunction,shIdentifier,shCase
  68. syn match   shTestOpr contained "[!=]\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>"
  69.  
  70. syn region  shDo transparent matchgroup=shStatement start="\<do\>" end="\<done\>" contains=ALLBUT,shFunction,shDoError,shCase
  71. syn region  shIf transparent matchgroup=shStatement start="\<if\>" end="\<fi\>" contains=ALLBUT,shFunction,shIfError,shCase
  72. syn region  shFor  matchgroup=shStatement start="\<for\>" end="\<in\>" contains=ALLBUT,shFunction,shInError,shCase
  73. syn region shCaseEsac transparent matchgroup=shStatement start="\<case\>" matchgroup=NONE end="\<in\>"me=s-1 contains=ALLBUT,shFunction,shCaseError nextgroup=shCaseEsac
  74. syn region shCaseEsac matchgroup=shStatement start="\<in\>" end="\<esac\>" contains=ALLBUT,shFunction,shCaseError
  75. syn region shCase matchgroup=shStatement contained start=")"  end=";;" contains=ALLBUT,shFunction,shCaseError,shCase
  76. syn region  shNone transparent matchgroup=shOperator start="{" end="}" contains=ALLBUT,shCurlyError,shCase
  77. syn region  shSubSh transparent matchgroup=shOperator start="(" end=")" contains=ALLBUT,shParenError,shCase
  78.  
  79. " Misc
  80. "=====
  81. syn match   shOperator        "[!&;|=]"
  82. syn match   shWrapLineOperator    "\\$"
  83. syn region  shCommandSub   start="`" skip="\\`" end="`" contains=ALLBUT,shFunction,shCommandSub,shTestOpr,shCase,shEcho
  84.  
  85. syn match   shSource    "^\.\s"
  86. syn match   shSource    "\s\.\s"
  87. syn region  shColon    start="^\s*:" end="$\|" end="#"me=e-1 contains=ALLBUT,shFunction,shTestOpr,shCase
  88.  
  89. " File redirection highlighted as operators
  90. "==========================================
  91. syn match    shRedir    "[0-9]\=>\(&[-0-9]\)\="
  92. syn match    shRedir    "[0-9]\=>>-\="
  93. syn match    shRedir    "[0-9]\=<\(&[-0-9]\)\="
  94. syn match    shRedir    "[0-9]<<-\="
  95.  
  96. " Shell Input Redirection (Here Documents)
  97. syn region shHereDoc matchgroup=shRedir start="<<-\=\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$"
  98. syn region shHereDoc matchgroup=shRedir start="<<-\=\s*\**EOF\**" matchgroup=shRedir end="^EOF$"
  99.  
  100. " Identifiers
  101. "============
  102. syn match  shIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>="me=e-1
  103. if exists("is_bash")
  104. syn region shIdentifier matchgroup=shStatement start="\<\(declare\|typeset\|local\|export\|set\|unset\)\>[^/]"me=e-1 matchgroup=shOperator skip="\\$" end="$\|[;&]" matchgroup=NONE end="#\|="me=e-1 contains=shTestError,shCurlyError,shWrapLineOperator
  105. elseif exists("is_kornshell")
  106. syn region shIdentifier matchgroup=shStatement start="\<\(typeset\|set\|export\|unset\)\>[^/]"me=e-1 matchgroup=shOperator skip="\\$" end="$\|[;&]" matchgroup=NONE end="#\|="me=e-1 contains=shTestError,shCurlyError,shWrapLineOperator
  107. else
  108. syn region shIdentifier matchgroup=shStatement start="\<\(set\|export\|unset\)\>[^/]"me=e-1 matchgroup=shOperator skip="\\$" end="$\|[;&]" matchgroup=NONE end="#\|="me=e-1 contains=shTestError,shCurlyError,shWrapLineOperator
  109. endif
  110.         " The [^/] in the start pattern is a kludge to avoid bad
  111.         " highlighting with cd /usr/local/lib...
  112.  
  113. syn region  shFunction transparent matchgroup=shFunctionName     start="^\s*\<[a-zA-Z_][a-zA-Z0-9_]*\>\s*()\s*{" end="}" contains=ALLBUT,shFunction,shCurlyError,shCase
  114. syn region shDeref         start="\${" end="}"
  115. syn match  shDeref         "\$\<[a-zA-Z_][a-zA-Z0-9_]*\>"
  116. syn match  shSpecialShellVar "\$[-#@*$?!0-9]"
  117.  
  118. " A bunch of useful sh keywords
  119. syn keyword shStatement    break cd chdir continue eval exec
  120. syn keyword shStatement    exit kill newgrp pwd read readonly
  121. syn keyword shStatement    return shift test trap
  122. syn keyword shStatement    ulimit umask wait
  123. syn keyword shConditional  else then elif while
  124.  
  125. if exists("is_kornshell") || exists("is_bash")
  126. syn keyword shStatement    bg fg jobs stop suspend
  127. syn keyword shFunction     function
  128. syn keyword shStatement    alias fc getopts hash history let print time
  129. syn keyword shStatement    times type whence unalias
  130. syn keyword shRepeat       select until
  131. if exists("is_bash")
  132. syn keyword shStatement    source bind builtin dirs
  133. syn keyword shStatement    disown enable help history
  134. syn keyword shStatement    logout popd pushd shopt
  135. else
  136. syn keyword shStatement    login newgrp
  137. endif
  138. endif
  139.  
  140. " Syncs
  141. " =====
  142. if !exists("sh_minlines")
  143.   let sh_minlines = 100
  144. endif
  145. exec "syn sync minlines=" . sh_minlines
  146. syn sync match shDoSync       grouphere  shDo       "\<do\>"
  147. syn sync match shDoSync       groupthere shDo       "\<done\>"
  148. syn sync match shIfSync       grouphere  shIf       "\<if\>"
  149. syn sync match shIfSync       groupthere shIf       "\<fi\>"
  150. syn sync match shForSync      grouphere  shFor      "\<for\>"
  151. syn sync match shForSync      groupthere shFor      "\<in\>"
  152. syn sync match shCaseEsacSync grouphere  shCaseEsac "\<case\>"
  153. syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
  154.  
  155. if !exists("did_sh_syntax_inits")
  156.   let did_sh_syntax_inits = 1
  157. " The default methods for highlighting.  Can be overridden later
  158.   hi link shSinglequote        shString
  159.   hi link shDoubleQuote        shString
  160.   hi link shHereDoc        shString
  161.   hi link shSource        shOperator
  162.   hi link shWrapLineOperator    shOperator
  163.   hi link shColon        shStatement
  164.   hi link shRedir        shOperator
  165.   hi link shSpecialShellVar    shShellVariables
  166.   hi link shDeref        shShellVariables
  167.   hi link shTestOpr        shConditional
  168.   hi link shEcho        shString
  169.   hi link shEmbeddedEcho    shString
  170.   hi link shInError        Error
  171.   hi link shCaseError        Error
  172.   hi link shEsacError        Error
  173.   hi link shDoError        Error
  174.   hi link shIfError        Error
  175.   hi link shCurlyError        Error
  176.   hi link shParenError        Error
  177.   hi link shTestError        Error
  178. if exists("is_kornshell")
  179.   hi link shDTestError        Error
  180. endif
  181.   hi link shCommandSub        Special
  182.   hi link shFunctionName    Function
  183.   hi link shStatement        Statement
  184.   hi link shConditional        Conditional
  185.   hi link shNumber        Number
  186.   hi link shString        String
  187.   hi link shComment        Comment
  188.   hi link shSpecial        Special
  189.   hi link shTodo        Todo
  190.   hi link shIdentifier        Identifier
  191.   hi link shShellVariables    PreProc
  192.   hi link shOperator        Operator
  193.   hi link shFunction            Function
  194.   hi link shRepeat        Repeat
  195. endif
  196.  
  197. let b:current_syntax = "sh"
  198.  
  199. " vim: ts=8
  200.